

// 等待 DOM 加载完成后再执行脚本
document.addEventListener("DOMContentLoaded", function () {


    const Classes = {};

    // 向后端发起 GET 请求
    fetch("/class/query/students/byTeacherName?teacherName=") // 替换为实际的学生数据接口路径
        .then(response => response.json()) // 解析响应为 JSON
        .then(data => {
            // 遍历返回的 JSON 数据
            data.data.forEach(student => {
                if (!Classes[student.classes]) {
                    Classes[student.classes] = [];
                }
                Classes[student.classes].push(student);
            });
            // 渲染班级和学生信息
            const dynamicClassesContainer = document.getElementById('dynamic-classes');
            for (const classes in Classes) {
                const classCard = document.createElement('div');
                classCard.className = 'class-card';

                const classTitle = document.createElement('div');
                classTitle.className = 'class-title';
                classTitle.innerHTML = `<h4>高一${classes}班</h4>`;

                const table = document.createElement('table');
                table.className = 'table';
                table.innerHTML = `
            <thead>
                <tr>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>性别</th>
                </tr>
            </thead>
            <tbody>
                ${Classes[classes].map(student => `
                    <tr>
                        <td>${student.Sno}</td>
                        <td>${student.Sname}</td>
                        <td>${student.gender}</td>
                    </tr>
                `).join('')}
            </tbody>
        `;
                classCard.appendChild(classTitle);
                classCard.appendChild(table);
                dynamicClassesContainer.appendChild(classCard);
        }})

        .catch(error => {
            console.error("获取学生数据时出错:", error);
        });
});

